<?php

	class product_size_DAO extends CI_Model{

		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		
		public function search($keyword){
			$where = "size_name like '%{$keyword}%'";
			$this->db->where($where);
			$query = $this->db->get("product_size");
			return $query->result_array();
		}
		
		public function getAll($category_level_2_id, $type_of_size_id){
			$this->db->where('category_level_2_id', $category_level_2_id);
			$this->db->where('type_of_size_id', $type_of_size_id);
			$query = $this->db->get("product_size");
			return $query->result_array();
		}
		
		public function get($id){
			$this->db->where('id', $id);
			$query = $this->db->get("product_size");
			if($query->num_rows() == 1){
				$tempQuery = $query->result();
				return $tempQuery[0];
			} else {
				return null;
			}
		}
		
		public function getById($id){
			$this->db->where('id', $id);
			$query = $this->db->get("product_size");
			$product_size_list = $query->result_array();
			if(sizeof($product_size_list) == 1){
				$product_size = $product_size_list[0];
				return $product_size;
			} else {
				return null;
			}
		}
		
		public function add($category){
			$this->db->insert("product_size", $category);
			return ($this->db->affected_rows() != 1) ? false : true;
		}
		
		public function update($id, $category_level_2_id, $type_of_size_id, $size_name){
			$data = array(
				'category_level_2_id' => $category_level_2_id,
				'type_of_size_id' => $type_of_size_id,
				'size_name' => $size_name
            );
			$this->db->where('id', $id);
			$this->db->update('product_size', $data);
			return ($this->db->affected_rows() != 1) ? false : true;
		}
		
		public function delete($id){
			$this->db->where('id', $id);
			$this->db->delete('product_size');
			return ($this->db->affected_rows() != 1) ? false : true;
		}
	}

?>